package homeWork;

public class Student implements Comparable{
    public int age;
    public int score ;
    public String name;


    public Student(int age, int score, String name) {
        this.age = age;
        this.score = score;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", score=" + score +
                ", name='" + name + '\'' +
                '}';
    }

    //实现比较方法
    @Override
    public int compareTo(Object o){
        Student i;
        if(o instanceof Student){
            i=(Student)o;
        }else {
            throw new RuntimeException("类型转换错误");
        }
        if(i.score>this.score){
            return 1;
        }
        else if (i.score<this.score){
            return -1;
        }else if (i.score==this.score){
            return 0;
        }
        return 0;
    }

}
